<template>
  <div id="app">
    <!-- 顶部导航栏 -->
    <div class="top-nav">
      <div class="logo">
        <img src="../Type/logo.png" alt="宠物商城" />
      </div>
      <a href="#" class="nav-item" @click.prevent="goToHome">首页</a>
      <router-link to="/personal-center" class="nav-item">个人中心</router-link>
      <div class="nav-item" style="background-color: #d9c596; font-weight: bold">账号管理</div>
    </div>
    <div class="sidebar">
      <ul>
        <li :class="{ active: activeTab === 'userInfor' }">
          <a @click="switchTab('userInfor')">个人信息</a>
        </li>
        <li :class="{ active: activeTab === 'shippingAddress' }">
          <a @click="switchTab('shippingAddress')">收货地址</a>
        </li>
        <!-- 添加更多导航项 -->
      </ul>
    </div>
    <div class="main-content">
      <UserInfor v-if="activeTab === 'userInfor'" />
      <ShippingAddress v-if="activeTab === 'shippingAddress'" />
    </div>
  </div>
</template>

<script>
import UserInfor from "./UserInfor.vue";
import ShippingAddress from "./ShippingAddress.vue";

export default {
  name: "App",
  components: {
    UserInfor,
    ShippingAddress,
  },
  data() {
    return {
      activeTab: "userInfor", // 默认激活个人信息标签
    };
  },
  methods: {
    goToHome() {
      this.$router.push("/");
    },
    switchTab(tab) {
      this.activeTab = tab;
    },
  },
};
</script>

<style scoped>
.logo {
  margin-right: 40px;
  height: 40px;
}
img {
  height: 100%;
}
.nav-item {
  width: 10%;
  color: black;
  text-decoration: none;
  height: 40px;
  text-align: center;
  line-height: 40px;
  cursor: pointer;
  font-size: 16px;
  border-radius: 18px;
  transition: all 0.3s;
  margin-right: 10px;
}
.nav-item:hover {
  background-color: rgba(0, 0, 0, 0.2);
}
#app {
  display: grid;
  grid-template-rows: auto 1fr;
  grid-template-columns: 200px 1fr;
  grid-template-areas:
    "header header"
    "sidebar main-content";
  gap: 10px;
  height: 100vh;
  width: 80%;
  margin: 0 auto;
}
.sidebar {
  width: 140px;
  height: 620px;
  background-color: #f4efd2;
  padding: 15px 0;
  margin-right: -1px;
  position: sticky;
  top: 120px;
  border-radius: 10px;
  text-align: center;
}
.sidebar ul {
  padding: 0;
  margin: 0;
}
.sidebar ul li {
  padding: 12px 15px;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s;
  color: #333;
  list-style: none;
}
.sidebar ul li:hover {
  background-color: #dcdbdb;
}
.sidebar ul li.active {
  background-color: #f4a46f;
  color: white;
}
.sidebar ul li a {
  display: block;
  width: 100%;
  height: 100%;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
}
.main-content {
  width: 100%;
  height: 620px;
  background-color: #f4efd2;
  padding: 15px 0;
  margin-right: -1px;
  position: sticky;
  top: 120px;
  border-radius: 10px;
  text-align: center;
}
.top-nav {
  grid-area: header;
  width: 100%;
  background-color: #f4efd2;
  color: black;
  padding: 15px 0;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: #bdbbb7 0px 0px 5px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  margin-bottom: 15px;
}
</style>
